<?php
//$Id$

class WebsiteApp extends App{

    function __construct(){
        parent::__construct();
    }

    // @param string 城市拼音
    private function initCity($city){
        $cityArray  = Core::getConfig('city.array');
        $cityIndex  = Core::getConfig('city.index');
        $defaultId  = Core::getConfig('default.cityid');

        if(isset($cityIndex[$city])){
            $this->cityInfo = $cityArray[$cityIndex[$city]];
            Core::setCookie('SudingkeCityId', $this->cityInfo[0], 60, '/', '.sudingke.net');
        }else{
            $defaultCityInfo = Core::getDefaultCityInfo();

            header('Location: http://'.$defaultCityInfo[2].'.sudingke.net'.$_SERVER['REQUEST_URI']);
            exit();
        }
    }

    /*
        根据Url结构唯一确定一个应用模型
        功能：通过路由，解析出 CityId, Action，Method，Params

        http://{$city}.sudingke.net/{$action}/{$method}/{$params}
    */
    function run(){
        $perfix = substr($_SERVER['HTTP_HOST'], 0, -13); // strlen('.sudingke.com')

        $this->initCity($perfix);

        @list(, $action, $param1, $param2) = explode('/', $_SERVER['REDIRECT_URL'], 4);

        $this->runAction($action, $param1, $param2);
    }
}
?>